Skip to content

fix(ws): prevent message list from scrolling on request pane tab switch - #8448

Merged
sid-bruno merged 15 commits into
usebruno:mainfrom
pooja-bruno:fix/ws-message-list-scroll-on-tab-switch
Jul 7, 2026
Merged

sid-bruno merged 15 commits into
usebruno:mainfrom
pooja-bruno:fix/ws-message-list-scroll-on-tab-switch

Conversation

@pooja-bruno

@pooja-bruno pooja-bruno commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

Switching request pane tabs (e.g. Message → Headers → Message) caused the WebSocket message list to jump/scroll pushing the expanded message out of view.

Added a Playwright regression test.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSocket message list scrolling, ensuring new messages reliably move into view.
    • Preserved message list scroll position across request pane tab switches, preventing unexpected jumps.
    • Prevented scroll “jank” when editor focus changes while interacting with the message list.
    • Enhanced handling for long WebSocket message content to better support overflow scenarios.
  • Tests
    • Added end-to-end coverage validating scroll restoration across tab switches.
    • Introduced a long WebSocket message fixture to exercise scrolling behavior.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Updates WebSocket message scrolling so remounts restore saved positions, new messages still scroll into view, and a regression test covers tab switching with a long-message fixture.

Changes

WebSocket scroll preservation

Layer / File(s) Summary
WsBody scroll handling
packages/bruno-app/src/components/RequestPane/WsBody/index.js
Restores saved scrollTop on remount, records scroll position changes, prevents focus-triggered jumps, and scrolls to the bottom when a new message is added.
Scroll regression test fixture and spec
tests/websockets/message-scroll.spec.ts, tests/websockets/fixtures/collection/ws-long-msg.bru
Adds a long-message WebSocket fixture and a Playwright spec that verifies scroll position is preserved or restored after switching request-pane tabs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: helloanoop, bijin-bruno, lohit-bruno, naman-bruno, sid-bruno

Poem

A scroll went down, a scroll came back,
Across the tabs it kept its track,
Long messages lined up just so,
And tests now watch the scrollbars flow,
Tiny waves in a WebSocket sea 🌊

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preventing the WebSocket message list from scrolling when switching request pane tabs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
tests/websockets/message-scroll/message-scroll.spec.ts (3)

17-44: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the container locator instead of re-querying by test id.

Line 37 re-queries page.getByTestId('ws-messages-container') even though container (line 17) already points to the same locator. As per path instructions, "Use locator variables for locators" — reusing it keeps the selector centralized and avoids drift if the test id ever changes in one place but not the other.

♻️ Proposed fix
     await selectRequestPaneTab(page, 'Headers');
-    await expect(page.getByTestId('ws-messages-container')).toBeHidden();
+    await expect(container).toBeHidden();
     await selectRequestPaneTab(page, 'Message');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/message-scroll/message-scroll.spec.ts` around lines 17 - 44,
The test re-queries the same ws-messages-container instead of reusing the
existing container locator, which breaks the “use locator variables for
locators” pattern. Update the message-scroll spec to reuse the container
variable throughout the flow, including after switching tabs and when asserting
visibility/scroll position, so the selector stays centralized in the
message-scroll test.

Source: Path instructions


29-44: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test only exercises scrollTop = 0, which trivially holds after a full remount.

Since switching tabs remounts WsBody (per the comment on line 36), the messages container is a brand-new DOM node whose scrollTop naturally starts at 0 — this passes even without any real scroll-position "preservation" logic, it only proves the old forced scroll-to-bottom is gone. Consider also asserting a non-zero starting scroll position (e.g. scroll to the middle) stays put after switching tabs back, if the intent is genuine position preservation rather than just "no forced scroll-to-bottom".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/message-scroll/message-scroll.spec.ts` around lines 29 - 44,
The current message-scroll test only verifies the trivial `scrollTop = 0` case,
which can pass on a fresh `WsBody` remount without proving preservation. Update
`message-scroll.spec.ts` around the `container.evaluate` and
`selectRequestPaneTab` steps to first scroll the `ws-messages-container` to a
non-zero position (for example, the middle of the list), then switch from
`Message` to `Headers` and back, and assert the restored `scrollTop` still
matches the original value. Use the existing `container`,
`selectRequestPaneTab`, and `ws-messages-container`/`ws-message-body-0`
selectors to keep the test focused on real scroll-position retention.

12-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Wrap the arrange/act/assert phases in test.step.

Path instructions call for promoting test.step "as much as possible so the generated reports are easier to read." Currently the whole body is one flat sequence; wrapping the "open request", "verify scrollable", "reset scroll", "switch tabs", and "assert no jump" phases in test.step blocks would make failures easier to localize in reports.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/message-scroll/message-scroll.spec.ts` around lines 12 - 45,
The message-scroll spec is still a flat sequence, so the report lacks clear
phase boundaries. In message-scroll.spec.ts, wrap the major arrange/act/assert
sections in test.step blocks inside the does not scroll the expanded message
list when switching request pane tabs test: opening the request, verifying the
container is scrollable, resetting scroll position, switching tabs, and
asserting the scroll position stays at the top. Keep the existing assertions and
helpers like openRequest, selectRequestPaneTab, and the ws-messages-container
checks, but group them into named steps so failures are easier to localize.

Source: Path instructions

packages/bruno-app/src/components/RequestPane/WsBody/index.js (1)

63-78: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Fix correctly gates scroll on new-message growth, not just mount.

Consolidating the scroll-to-bottom into this effect and keying it off messages.length > prevMessagesLengthRef.current (instead of the old messages.length > 0 check) is the right fix — since prevMessagesLengthRef is seeded with the initial messages.length, tab-switch/remounts won't spuriously trigger a jump to the bottom.

One optional improvement: the DOM write (container.scrollTop = container.scrollHeight) happens in a plain useEffect, which runs after paint — this can cause a visible one-frame jump for a longer message list. Consider useLayoutEffect so the scroll adjustment happens before the browser paints.

♻️ Proposed tweak
-import { useCallback, useEffect, useRef, useState } from 'react';
+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
...
-  useEffect(() => {
+  useLayoutEffect(() => {
     if (messages.length > prevMessagesLengthRef.current) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js` around lines
63 - 78, The scroll-to-bottom logic in WsBody’s useEffect is correct for only
handling true message growth via prevMessagesLengthRef, but the DOM update is
still happening after paint and can cause a visible jump. Move the scroll
adjustment in the messages.length effect to useLayoutEffect so
messagesContainerRef.current.scrollTop is set before paint, while keeping the
existing new-message gate and the expansion/selection updates tied to the latest
message UID.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js`:
- Around line 63-78: The scroll-to-bottom logic in WsBody’s useEffect is correct
for only handling true message growth via prevMessagesLengthRef, but the DOM
update is still happening after paint and can cause a visible jump. Move the
scroll adjustment in the messages.length effect to useLayoutEffect so
messagesContainerRef.current.scrollTop is set before paint, while keeping the
existing new-message gate and the expansion/selection updates tied to the latest
message UID.

In `@tests/websockets/message-scroll/message-scroll.spec.ts`:
- Around line 17-44: The test re-queries the same ws-messages-container instead
of reusing the existing container locator, which breaks the “use locator
variables for locators” pattern. Update the message-scroll spec to reuse the
container variable throughout the flow, including after switching tabs and when
asserting visibility/scroll position, so the selector stays centralized in the
message-scroll test.
- Around line 29-44: The current message-scroll test only verifies the trivial
`scrollTop = 0` case, which can pass on a fresh `WsBody` remount without proving
preservation. Update `message-scroll.spec.ts` around the `container.evaluate`
and `selectRequestPaneTab` steps to first scroll the `ws-messages-container` to
a non-zero position (for example, the middle of the list), then switch from
`Message` to `Headers` and back, and assert the restored `scrollTop` still
matches the original value. Use the existing `container`,
`selectRequestPaneTab`, and `ws-messages-container`/`ws-message-body-0`
selectors to keep the test focused on real scroll-position retention.
- Around line 12-45: The message-scroll spec is still a flat sequence, so the
report lacks clear phase boundaries. In message-scroll.spec.ts, wrap the major
arrange/act/assert sections in test.step blocks inside the does not scroll the
expanded message list when switching request pane tabs test: opening the
request, verifying the container is scrollable, resetting scroll position,
switching tabs, and asserting the scroll position stays at the top. Keep the
existing assertions and helpers like openRequest, selectRequestPaneTab, and the
ws-messages-container checks, but group them into named steps so failures are
easier to localize.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 38f686a3-e1ab-47f3-8ed0-a6c964413971

📥 Commits

Reviewing files that changed from the base of the PR and between 4f31e9b and 87693f4.

📒 Files selected for processing (6)
  • packages/bruno-app/src/components/RequestPane/WsBody/index.js
  • tests/websockets/message-scroll/fixtures/collection/bruno.json
  • tests/websockets/message-scroll/fixtures/collection/collection.bru
  • tests/websockets/message-scroll/fixtures/collection/ws-long-msg.bru
  • tests/websockets/message-scroll/init-user-data/preferences.json
  • tests/websockets/message-scroll/message-scroll.spec.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/websockets/message-scroll.spec.ts (2)

37-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the container locator variable.

Line 37 re-queries page.getByTestId('ws-messages-container') instead of reusing the container variable declared at Line 17.

♻️ Suggested fix
-    await expect(page.getByTestId('ws-messages-container')).toBeHidden();
+    await expect(container).toBeHidden();
As per path instructions, "Use locator variables for locators."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/message-scroll.spec.ts` at line 37, The test re-queries the
websocket messages container instead of reusing the existing locator variable.
Update the assertion in the message-scroll spec to use the already declared
container locator from the test setup, so the same locator is reused
consistently throughout the test.

Source: Path instructions


12-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Wrap test phases in test.step for readable reports.

The test lacks any test.step segmentation despite multiple logical phases (open request, verify scrollable, reset scroll, switch tabs, verify scroll position).

♻️ Suggested refactor
   test('does not scroll the expanded message list when switching request pane tabs', async ({
     pageWithUserData: page
   }) => {
-    await openRequest(page, COLLECTION_NAME, LONG_MSG_REQ);
-
-    const container = page.getByTestId('ws-messages-container');
-    await expect(container).toBeVisible();
-
-    // The first (long) message is expanded by default. Ensure its editor is
-    // rendered so the container has enough content to overflow.
-    await expect(page.getByTestId('ws-message-body-0')).toBeVisible();
-
-    // the container must actually be scrollable.
-    await expect
-      .poll(() => container.evaluate((el) => el.scrollHeight - el.clientHeight))
-      .toBeGreaterThan(0);
-
-    // Start from the top of the list.
-    await container.evaluate((el) => {
-      el.scrollTop = 0;
-    });
-    await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0);
-
-    // Switch away from the Message tab and back — this remounts WsBody.
-    await selectRequestPaneTab(page, 'Headers');
-    await expect(page.getByTestId('ws-messages-container')).toBeHidden();
-    await selectRequestPaneTab(page, 'Message');
-
-    await expect(container).toBeVisible();
-    await expect(page.getByTestId('ws-message-body-0')).toBeVisible();
-
-    // The scroll position must not have jumped to the bottom on remount.
-    await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0);
+    const container = page.getByTestId('ws-messages-container');
+
+    await test.step('open request with long message', async () => {
+      await openRequest(page, COLLECTION_NAME, LONG_MSG_REQ);
+      await expect(container).toBeVisible();
+      await expect(page.getByTestId('ws-message-body-0')).toBeVisible();
+      await expect
+        .poll(() => container.evaluate((el) => el.scrollHeight - el.clientHeight))
+        .toBeGreaterThan(0);
+    });
+
+    await test.step('reset scroll to top', async () => {
+      await container.evaluate((el) => {
+        el.scrollTop = 0;
+      });
+      await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0);
+    });
+
+    await test.step('switch away from and back to Message tab', async () => {
+      await selectRequestPaneTab(page, 'Headers');
+      await expect(container).toBeHidden();
+      await selectRequestPaneTab(page, 'Message');
+      await expect(container).toBeVisible();
+      await expect(page.getByTestId('ws-message-body-0')).toBeVisible();
+    });
+
+    await test.step('verify scroll position is preserved', async () => {
+      await expect.poll(() => container.evaluate((el) => el.scrollTop)).toBe(0);
+    });
   });
As per path instructions, "Promote the use of `test.step` as much as possible so the generated reports are easier to read."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/websockets/message-scroll.spec.ts` around lines 12 - 45, The test in
message-scroll.spec.ts has several distinct phases but is written as one block,
which makes Playwright reports harder to read. Split the flow inside the
existing test('does not scroll the expanded message list when switching request
pane tabs', ...) into multiple test.step sections for the main actions: opening
the request via openRequest, verifying the container is scrollable, resetting
scrollTop, switching tabs with selectRequestPaneTab, and checking the final
scroll position. Keep the existing assertions and helpers (openRequest,
selectRequestPaneTab, ws-messages-container, ws-message-body-0) the same, just
wrap each logical phase in clear test.step labels.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/websockets/message-scroll.spec.ts`:
- Line 37: The test re-queries the websocket messages container instead of
reusing the existing locator variable. Update the assertion in the
message-scroll spec to use the already declared container locator from the test
setup, so the same locator is reused consistently throughout the test.
- Around line 12-45: The test in message-scroll.spec.ts has several distinct
phases but is written as one block, which makes Playwright reports harder to
read. Split the flow inside the existing test('does not scroll the expanded
message list when switching request pane tabs', ...) into multiple test.step
sections for the main actions: opening the request via openRequest, verifying
the container is scrollable, resetting scrollTop, switching tabs with
selectRequestPaneTab, and checking the final scroll position. Keep the existing
assertions and helpers (openRequest, selectRequestPaneTab,
ws-messages-container, ws-message-body-0) the same, just wrap each logical phase
in clear test.step labels.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8baca53d-83ad-434f-91ad-cd1d4a4dfde1

📥 Commits

Reviewing files that changed from the base of the PR and between 87693f4 and 8317aa6.

📒 Files selected for processing (2)
  • tests/websockets/fixtures/collection/ws-long-msg.bru
  • tests/websockets/message-scroll.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • tests/websockets/fixtures/collection/ws-long-msg.bru

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/bruno-app/src/components/RequestPane/WsBody/index.js (1)

14-15: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Unbounded module-level scrollPositions map — never evicted.

scrollPositions lives at module scope and only ever grows (handleScroll sets an entry per item.uid, line 97). Nothing removes an entry when a WS request is deleted or a collection is closed, so this Map accumulates stale entries for the entire app session. Low individual entry cost, but it's an unbounded leak with no cleanup path.

♻️ Suggested cleanup approach
+// Consider clearing stale entries when items are removed, e.g. via a
+// dispatched delete-item listener, or cap the map size with an LRU eviction.
 const scrollPositions = new Map();

Consider tying eviction to item deletion (e.g., listen for the delete-request action) or capping the map with a simple LRU strategy.

Also applies to: 94-99

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js` around lines
14 - 15, The module-level scrollPositions Map in WsBody is unbounded and never
evicted, so stale entries can accumulate for the whole session. Update the
WsBody component’s scroll handling (especially handleScroll and the uid-based
set/get flow) to remove entries when a WS request/item is deleted or a
collection is closed, or replace it with a capped/LRU cache so old scroll
positions are discarded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/bruno-app/src/components/RequestPane/WsBody/index.js`:
- Around line 14-15: The module-level scrollPositions Map in WsBody is unbounded
and never evicted, so stale entries can accumulate for the whole session. Update
the WsBody component’s scroll handling (especially handleScroll and the
uid-based set/get flow) to remove entries when a WS request/item is deleted or a
collection is closed, or replace it with a capped/LRU cache so old scroll
positions are discarded.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0f46b68-6439-4bfa-a29c-50c34987c4d9

📥 Commits

Reviewing files that changed from the base of the PR and between 79bce3c and 0093b62.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/RequestPane/WsBody/index.js
  • tests/websockets/message-scroll.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/websockets/message-scroll.spec.ts

@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Jul 6, 2026
@sid-bruno
sid-bruno merged commit 958ca49 into usebruno:main Jul 7, 2026
13 of 16 checks passed
ravindra-bruno pushed a commit to ravindra-bruno/bruno that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants